﻿@using Model;
@{
    if (Roles.IsUserInRole(UsersRoles.Admin))
    {
        Layout = "~/Admin/_AdminSiteLayout.cshtml";
    }
    else
    {
        Layout = "~/Shared/_SiteLayout.cshtml";
    }
    Page.Title = "View User Profile";

    int requestId = UrlData[0].AsInt();// Request.Form["Id"].AsInt();

    Profile aProfile = SiteHelper.GetProfileByUserId(requestId);

}
<form method="post" action="">
<fieldset>
    @if (aProfile != null)
    {
        <legend>Profile of @aProfile.FullName</legend>
        <table class="table">
            <tbody>
                <tr>
                    <td class="user-info-label">
                        Name
                    </td>
                    <td>
                        :
                    </td>
                    <td class="user-info">
                        @aProfile.FirstName
                    </td>
                </tr>
                <tr>
                    <td class="user-info-label">
                        Father's Name
                    </td>
                    <td>
                        :
                    </td>
                    <td class="user-info">
                        @aProfile.FathersName
                    </td>
                </tr>
                <tr>
                    <td class="user-info-label">
                        Mother's Name
                    </td>
                    <td>
                        :
                    </td>
                    <td class="user-info">
                        @aProfile.MothersName
                    </td>
                </tr>
                <tr>
                    <td class="user-info-label">
                        Village
                    </td>
                    <td>
                        :
                    </td>
                    <td class="user-info">
                        @aProfile.AddressLine1 , @aProfile.AddressLine2
                    </td>
                </tr>
                <tr>
                    <td class="user-info-label">
                        Birth Day
                    </td>
                    <td>
                        :
                    </td>
                    <td class="user-info">
                        @aProfile.BirthDate
                    </td>
                </tr>
                <tr>
                    <td class="user-info-label">
                        Class
                    </td>
                    <td>
                        :
                    </td>
                    <td class="user-info">
                        @aProfile.ReadingClass
                    </td>
                </tr>
                <tr>
                    <td class="user-info-label">
                        School
                    </td>
                    <td>
                        :
                    </td>
                    <td class="user-info">
                        My School
                    </td>
                </tr>
                <tr>
                    <td class="user-info-label">
                        Group
                    </td>
                    <td>
                        :
                    </td>
                    <td class="user-info">
                        @aProfile.ReadingGroup
                    </td>
                </tr>
                <tr>
                    <td class="user-info-label">
                        Mobile
                    </td>
                    <td>
                        :
                    </td>
                    <td class="user-info">
                        @aProfile.Mobile
                    </td>
                </tr>
                <tr>
                    <td class="user-info-label">
                        Email
                    </td>
                    <td>
                        :
                    </td>
                    <td class="user-info">
                        @aProfile.Email
                    </td>
                </tr>
                <tr>
                    <td class="user-info-label">
                        Facebook
                    </td>
                    <td>
                        :
                    </td>
                    <td class="user-info">
                        <a href="http://www.facebook.com/@aProfile.FbUserName" target="_blank">@aProfile.FbUserName</a>
                    </td>
                </tr>
                <tr>
                    <td class="user-info-label">
                        Twitter
                    </td>
                    <td>
                        :
                    </td>
                    <td class="user-info">
                        <a href="http://www.twitter.com/@aProfile.TwitterUserName" target="_blank">@aProfile.TwitterUserName</a>
                    </td>
                </tr>
            </tbody>
        </table>

    }
    else
    {
        <legend>Opps</legend>
        <p class="message error">
            No Profile Found
        </p>
    }
    @{

        List<SelectListItem> listItem = new List<SelectListItem>();

        List<Question> answeredQuestionList = SiteHelper.GetAnsweredQuestionsAUserByuserId(requestId);

        int totalAttendQuestion = 0;
        int rightAnswer = 0;
        int wrongAnswer = 0;
        int notAnswered = 0;
        double percentageResult = 0.0;

        if (answeredQuestionList.Count > 0)
        {

            percentageResult = (double)answeredQuestionList.Sum(x => x.Results);
            percentageResult = percentageResult / answeredQuestionList.Count;

            totalAttendQuestion = answeredQuestionList.Count;
            rightAnswer = answeredQuestionList.Count(x => x.IsAnswered == 2);
            wrongAnswer = answeredQuestionList.Count(x => x.IsAnswered == 3);

            notAnswered = totalAttendQuestion - (rightAnswer + wrongAnswer);

        }
        List<Question> questionList = new List<Question>();
        foreach (Question item in answeredQuestionList)
        {
            if (string.IsNullOrEmpty(item.AnswerStatus))
            {
                //answeredQuestionList.Remove(item);

                item.AnswerStatus = SiteHelper.GetStatus(item.IsAnswered);

                questionList.Add(item);
            }
        }
        answeredQuestionList = questionList;

        var grid = new WebGrid(source: answeredQuestionList, rowsPerPage: WebSite.RowsPerPage);

        if (answeredQuestionList.Count > 0)
        {
        <hr />
        <label>
            Asnwer Sheet</label>
        <div id="grid">
            @grid.GetHtml(
                tableStyle: "gridTable",
                headerStyle: "gridTableHeader",
                rowStyle: "rowstyle",
                alternatingRowStyle: "alternaterowstyle",
                columns: grid.Columns(
                grid.Column("Questions", "Questions"),
                grid.Column("TotalAnsweringTime", "Total Answering Time", style: "text-align-center"),
                grid.Column("SpendingTime", "Spending Time", style: "text-align-center"),
                grid.Column("IsAnswered", "Answer Condition", style: "text-align-center"),
                               grid.Column("AnswerStatus", "Answer Status", style: "text-align-center AnswerStatus"),
                grid.Column("Results", format: @<span>@item.Results.ToString("N")</span>, style: "text-align-center")
            )
            )
        </div>
        <hr />
        <p class="result-status">
            <span>Response Time:
                @String.Format("{0:0.00}", percentageResult) % </span><span>Total Question Attend : @totalAttendQuestion
                </span><span class="RightAnswered">Right Answer :
                    @rightAnswer
                </span><span class="WrongAnswered">Wrong Answer : @wrongAnswer</span><span class="NotAnswered">
                    Not Answered : @notAnswered
                </span>
        </p>
        }
        else
        {
        <hr />
        <p class="message error">
            This user did not answer any question
        </p>
        }
    }
</fieldset>
</form>
<script src="@Href("~/Scripts/jquery-1.6.2.min.js")" type="text/javascript"></script>
<script src="@Href("~/Scripts/Answer-table-color.js")" type="text/javascript"></script>
